<?php
class goods extends PHPUnit_Framework_TestCase{

    public function setUp()
    {
		$this->object = kernel::single('tbdata_api_tbapi');
		$this->cat_model = app::get('tbdata')->model('cats');
		$this->fetch_props_model = app::get('tbdata')->model('fetch_props');
		$this->product_model = app::get('tbdata')->model('product');
    }

    public function testGetcat(){

		$db = kernel::database();
		$sql = "select * from sdb_tbdata_product where cid=1512";
		$db_rs = $db->exec($sql);
		$rs = $db_rs['rs'];

		$fp = fopen('d:\1512.csv', 'w');
		$i = 0;
		while($product = mysql_fetch_assoc($rs)){

			$props_str = $product['props_str'];
			$props_str = substr($props_str,strrpos($props_str,':')+1);

			$taoke = kernel::single('tbdata_api_taoke');

			$params = array('cid'=>$product['cid'],'keyword'=>$props_str,'pid'=>'10080582','sort'=>'credit_desc','page_size'=>10);
			$items = $taoke->get_taoke_items($params);

			foreach ((array)$items['taobaoke_items_get_response']['taobaoke_items']['taobaoke_item'] as $fields) {
				$fields['product_id'] = $product['id'];
				$fields['keywork'] = $props_str;
				if($i==0){
					fputcsv($fp, array_keys($fields));
					$i++;
				}
				fputcsv($fp, $fields);
			}
			if($i++%50==0){
				echo $i."\n";
			}
		}
	}
}
